package rdd

import org.apache.spark.{SparkConf, SparkContext}

object WordCountLocal {

  def main(args: Array[String]): Unit = {

    val inputFile =  "/Users/stephen/Desktop/test.txt"
    val conf = new SparkConf().setAppName("WordCount").setMaster("local[2]")
    val sc = new SparkContext(conf)
    val textFile = sc.textFile(inputFile)
    val wordCount = textFile.flatMap(line => line.split(" ")).map(word => (word, 1)).reduceByKey((a, b) => a + b)
    wordCount.foreach(println)

    sc.stop()
  }
}
